package com.sgcc.operate.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.sgcc.operate.domain.OPrizeCost;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sgcc.common.log.annotation.Log;
import com.sgcc.common.log.enums.BusinessType;
import com.sgcc.common.security.annotation.PreAuthorize;
import com.sgcc.operate.domain.OActiRule;
import com.sgcc.operate.service.IOActiRuleService;
import com.sgcc.common.core.web.controller.BaseController;
import com.sgcc.common.core.web.domain.AjaxResult;
import com.sgcc.common.core.utils.poi.ExcelUtil;
import com.sgcc.common.core.web.page.TableDataInfo;

/**
 * 活动规则Controller
 * 
 * @author sgcc
 * @date 2021-03-25
 */
@RestController
@RequestMapping("/actirule")
public class OActiRuleController extends BaseController
{
    @Autowired
    private IOActiRuleService oActiRuleService;

    /**
     * 查询活动规则列表
     */
    //@PreAuthorize(hasPermi = "operate:actirule:list")
    @GetMapping("/list")
    public TableDataInfo list(OActiRule oActiRule)
    {
        startPage();
        List<OActiRule> list = oActiRuleService.selectOActiRuleList(oActiRule);
        return getDataTable(list);
    }

    /**
     * 导出活动规则列表
     */
    //@PreAuthorize(hasPermi = "operate:actirule:export")
    @Log(title = "活动规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OActiRule oActiRule) throws IOException
    {
        List<OActiRule> list = oActiRuleService.selectOActiRuleList(oActiRule);
        ExcelUtil<OActiRule> util = new ExcelUtil<OActiRule>(OActiRule.class);
        util.exportExcel(response, list, "actirule");
    }

    /**
     * 获取活动规则详细信息
     */
    //@PreAuthorize(hasPermi = "operate:actirule:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(oActiRuleService.selectOActiRuleById(id));
    }

    /**
     * 新增活动规则
     */
    //@PreAuthorize(hasPermi = "operate:actirule:add")
    @Log(title = "活动规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OActiRule oActiRule)
    {
        return toAjax(oActiRuleService.insertOActiRule(oActiRule));
    }

    /**
     * 修改活动规则
     */
    //@PreAuthorize(hasPermi = "operate:actirule:edit")
    @Log(title = "活动规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OActiRule oActiRule)
    {
        return toAjax(oActiRuleService.updateOActiRule(oActiRule));
    }

    /**
     * 删除活动规则
     */
    //@PreAuthorize(hasPermi = "operate:actirule:remove")
    @Log(title = "活动规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(oActiRuleService.deleteOActiRuleByIds(ids));
    }




//    /**
//     * 配置活动的时候，通过活动的id，获取奖品信息
//     */
//    @PostMapping(value = "getProzeCostList")
//    public AjaxResult getProzeCostList(OActiRule oActiRule) {
//        List<OPrizeCost> result = oActiRuleService.getProzeCostList(oActiRule);
//        return AjaxResult.success(result);
//    }
}
